package modeling;

import java.io.File;


/**
 * @author Mathieu Rousseau
 * @email mathieu.rousseau3@mail.mcgill.ca
 */


/** ------------------------------------------------------------------------------------------------------------------
 * start of MicroarrayToIFwithGDnormalization class
 * ------------------------------------------------------------------------------------------------------------------  **/
public class MicroarrayToIFwithGDnormalization {


	/*  start of main method  */
	public static void main(String[] args){
		
		
		//  specify the input and output paths that will be used
		String inputPath = "MicroarrayToIF/Input/";
		String outputPath = "MicroarrayToIF/Output/";
		
		//  declare the parameters that will be needed to run the programs
		String filenameConditionOneGD, filenameConditionTwoGD, filenameBackgroundGD;
		String filenameConditionOneExperimental, filenameConditionTwoExperimental, filenameBackgroundExperimental;
		double background_cutoff_percentage, stdev_cutoff_percentage;		
		
		
		
		
		
		
		
		
		
		
		/** ------------------------------------------------------------------------------------------------------------------
		 * 
		 * 
		 * 								HARDCODING OF PARAMETERS
		 * 
		 * 
		 * ------------------------------------------------------------------------------------------------------------------  */
		
		
		/*****************************************************************
		 * 
		 *				       CUTOFF SPECIFICATIONS
		 *
		 *****************************************************************/
		//  specify the background cutoff percentage for the MicroarrayToIF program to use
		background_cutoff_percentage = 150;
		
		//  specify the standard deviation cutoff percentage for the MicroarrayToIF program to use (the stdev has to be smaller than this percentage of the IF value)
		stdev_cutoff_percentage = 75;

		
		/********************************************************************
		 * 
		 *				NORMALIZATION INPUT FILE SPECIFICATION
		 *
		 ********************************************************************/
		//  specify the filenames to calculate the normalization factor
		
		//  Condition One is the reference condition
		filenameConditionOneGD = "GD_BMH.txt";
		
		//  Condition Two is the condition that is being normalized to the reference condition
		//  It is Condition Two that will need to be multiplied by the calculated normalization factor
		filenameConditionTwoGD = "GD_Nalm6.txt";
		
		//  Background is generally the BAC experiment that is used to calculate the IF values for both of the conditions
		filenameBackgroundGD = "GD_BAC.txt";
		
		
		/******************************************************************
		 * 	
		 *				EXPERIMENTAL INPUT FILE SPECIFICATION
		 *
		 ******************************************************************/
		//  Condition One here should match the Condition One used for the normalization above  
		filenameConditionOneExperimental = "HoxA_BMH.txt";
		
		//  Condition Two here should match the Condition Two used for the normalization above
		filenameConditionTwoExperimental = "HoxA_Nalm6.txt";
		
		//  Background is generally the BAC experiment that is used to calculate the IF values for both of the conditions
		filenameBackgroundExperimental = "HoxA_BAC.txt";
		
		
		/** ------------------------------------------------------------------------------------------------------------------
		 * 
		 * 
		 * 								END OF HARDCODING OF PARAMETERS
		 * 
		 * 
		 * ------------------------------------------------------------------------------------------------------------------  */
		
		
		
		
		
		
		
		
		
		
		//  run the MicroarrayToIF program on the IF dataset for the Gene Desert for the first condition
		String[] argsMicroarrayToIF = new String[4];
		argsMicroarrayToIF[0] = filenameConditionOneGD;
		argsMicroarrayToIF[1] = filenameBackgroundGD;
		argsMicroarrayToIF[2] = String.valueOf(background_cutoff_percentage);
		argsMicroarrayToIF[3] = String.valueOf(stdev_cutoff_percentage);
		
		MicroarrayToIF IFcalculator = new MicroarrayToIF();
		IFcalculator.run(argsMicroarrayToIF);
		
		//  run the MicroarrayToIF program on the second IF dataset for the Gene Desert for the second condition		
		argsMicroarrayToIF = new String[4];
		argsMicroarrayToIF[0] = filenameConditionTwoGD;
		argsMicroarrayToIF[1] = filenameBackgroundGD;
		argsMicroarrayToIF[2] = String.valueOf(background_cutoff_percentage);
		argsMicroarrayToIF[3] = String.valueOf(stdev_cutoff_percentage);
		
		IFcalculator = new MicroarrayToIF();
		IFcalculator.run(argsMicroarrayToIF);
		
		
		
		//  use the output of the MicroarrayToIF program to calculate the normalization factor
		String prefix = "cleaned_input_file_";
		
		//  move the two output files needed to the input folder
		
		File fileToMove = new File(outputPath + prefix + filenameConditionOneGD);
		fileToMove.renameTo(new File(inputPath + prefix + filenameConditionOneGD));
		
		fileToMove = new File(outputPath + prefix + filenameConditionTwoGD);
		fileToMove.renameTo(new File(inputPath + prefix + filenameConditionTwoGD));
		
		fileToMove = new File(outputPath + prefix + filenameBackgroundGD);
		fileToMove.renameTo(new File(inputPath + prefix + filenameBackgroundGD));
		
		
		//  calculate the normalization factor with the cleaned input files generated by the MicroarrayToIF program
		String[] argsNormalizationGeneDesert = new String[5];
		argsNormalizationGeneDesert[0] = prefix + filenameConditionOneGD;
		argsNormalizationGeneDesert[1] = prefix + filenameConditionTwoGD;
		argsNormalizationGeneDesert[2] = prefix + filenameBackgroundGD;
		argsNormalizationGeneDesert[3] = inputPath;
		argsNormalizationGeneDesert[4] = outputPath;
		
		NormalizationGeneDesert normalizer = new NormalizationGeneDesert();
		double normalizationFactor = normalizer.runAndReturn(argsNormalizationGeneDesert);
		
		
		//  move the files back to the output folder where they originated
		fileToMove = new File(inputPath + prefix + filenameConditionOneGD);
		fileToMove.renameTo(new File(outputPath + prefix + filenameConditionOneGD));
		
		fileToMove = new File(inputPath + prefix + filenameConditionTwoGD);
		fileToMove.renameTo(new File(outputPath + prefix + filenameConditionTwoGD));
		
		fileToMove = new File(inputPath + prefix + filenameBackgroundGD);
		fileToMove.renameTo(new File(outputPath + prefix + filenameBackgroundGD));
		
		
		
		
		//  run the MicroarrayToIF program on the IF dataset for the first experimental condition
		argsMicroarrayToIF = new String[4];
		argsMicroarrayToIF[0] = filenameConditionOneExperimental;
		argsMicroarrayToIF[1] = filenameBackgroundExperimental;
		argsMicroarrayToIF[2] = String.valueOf(background_cutoff_percentage);
		argsMicroarrayToIF[3] = String.valueOf(stdev_cutoff_percentage);
		
		IFcalculator = new MicroarrayToIF();
		IFcalculator.run(argsMicroarrayToIF);
				
		//  run the MicroarrayToIF program on the IF dataset for the second experimental condition
		//  use the normalization factor calculated above
		argsMicroarrayToIF = new String[5];
		argsMicroarrayToIF[0] = filenameConditionTwoExperimental;
		argsMicroarrayToIF[1] = filenameBackgroundExperimental;
		argsMicroarrayToIF[2] = String.valueOf(background_cutoff_percentage);
		argsMicroarrayToIF[3] = String.valueOf(stdev_cutoff_percentage);
		argsMicroarrayToIF[4] = String.valueOf(normalizationFactor);
		
		IFcalculator = new MicroarrayToIF();
		IFcalculator.run(argsMicroarrayToIF);
	}/*  end of main method  */

	
}/*  end of MicroarrayToIFwithGDnormalization class  */